<template>
	<el-form :model="ruleForm2" :rules="rules2" ref="formRef" label-position="left" label-width="0px" class="login-container">
		<h3 class="title">用户注册</h3>
		<el-form-item prop="account">
			<el-input type="text" v-model="ruleForm2.account" clearable autocomplete="off" placeholder="账号"></el-input>
		</el-form-item>
        <el-form-item prop="email">
            <el-input type="text" v-model="ruleForm2.email" clearable autocomplete="off" placeholder="邮箱"></el-input>
        </el-form-item>
		<el-form-item prop="password">
            <el-form-item prop="password">
                <el-input type="password" v-model="ruleForm2.password"  clearable autocomplete="off" placeholder="密码" style="width:350px;"></el-input>
            </el-form-item>
		</el-form-item>
		<el-form-item style="width:100%;">
			<el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="loading">注册用户</el-button>
		</el-form-item>
	</el-form>
</template>

<script setup>
//import NProgress from 'nprogress';
import {Base64} from 'js-base64';
const router = useRouter();
const {proxy} = getCurrentInstance();

const ruleForm2 = ref({
    account: null,
    password: null,
    email:null
});
const loading = ref(false);

const rules2 = {
    account: [{ required: true, trigger: "blur", message: "请输入账号" }],
    password: [{ required: true, trigger: "blur", message: "请输入密码" }],
    email: [{ required: true, trigger: "blur", message: "请输入邮箱" }]
};

function init() {
    let account = null;
    let pwd = null;
    if (account) {
        ruleForm2.value.account = account;
        ruleForm2.value.password = password;
        ruleForm2.value.email = email;
    }
}
init();

function handleSubmit2() {
    proxy.$refs.formRef.validate(valid => {
        if (valid) {
            loading.value = true;
            var params={"username":ruleForm2.value.account,"password":ruleForm2.value.password,"email":ruleForm2.value.email};
            proxy.request.post('/register', JSON.stringify(params), {
                headers: {
                    'Content-Type': 'application/json'
                }
            }).then((res) => {
                proxy.$modal.msgSuccess(res.data.msg);
                router.push({ path: "/login" });
            }).catch((err) => {
                loading.value = false;
            });
        } else {
            loading.value = false;
            return false;
        }
    });
}

</script>

<style lang="scss" scoped>
.login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
    }
    .remember {
        margin: 0px 0px 35px 0px;
    }
}
</style>
